package com.mf.gateway.filter;

import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * JWT过滤器
 * User: zhaoming
 * DateTime: 2017-12-24
 * To change this template use File | Settings | File Templates.
 **/
public class AccessTokenFilter extends ZuulFilter {

	private static Logger logger = LoggerFactory.getLogger(AccessTokenFilter.class);

	@Override
	public String filterType() {
		return "pre";
	}

	@Override
	public int filterOrder() {
		return 0;
	}

	@Override
	public boolean shouldFilter() {
		return true;
	}

	@Override
	public Object run() {
		RequestContext requestContext = RequestContext.getCurrentContext();
		HttpServletRequest request = requestContext.getRequest();
		String uri = request.getRequestURI();
		if(uri.contains("/api/wx/")){
		} else {
			requestContext.setSendZuulResponse(false);
			requestContext.setResponseStatusCode(HttpServletResponse.SC_UNAUTHORIZED);
			requestContext.setResponseBody("access token is empty");
		}
		return null;
	}
}
